Fix overloading with a typevar missing#11617
Closed
A5rocks wants to merge 4 commits intopython:masterfrom
Closed
Conversation
This comment has been minimized.
This comment has been minimized.
Collaborator
Author
|
oh that broke terribly didn't it. |
This comment has been minimized.
This comment has been minimized.
Member
|
I think that the given example is not ideal. Because typevar should not even be used in this example: T = typing.TypeVar("T", bound=A)
@typing.overload
def f(a: T) -> None:
...
@typing.overload
def f(*, copy: bool = False) -> None:
...
def f(a: T = ..., *, copy: bool = False) -> None:
...Should be: @typing.overload
def f(a: A) -> None:
...
@typing.overload
def f(*, copy: bool = False) -> None:
...
def f(a: A = ..., *, copy: bool = False) -> None:
...Maybe you should also add an example, where |
Collaborator
Author
|
The given example was an oversimplification of the original, which can be simplified to: import typing
import collections.abc as collections
class BaseSlashCommand:
...
BaseSlashCommandT = typing.TypeVar("BaseSlashCommandT", bound=BaseSlashCommand)
@typing.overload
def with_slash_command(command: BaseSlashCommandT, /) -> BaseSlashCommandT:
...
@typing.overload
def with_slash_command(
*, copy: bool = False
) -> collections.Callable[[BaseSlashCommandT], BaseSlashCommandT]:
...
def with_slash_command(
command: BaseSlashCommandT = ..., /, *, copy: bool = False
) -> typing.Union[BaseSlashCommandT, collections.Callable[[BaseSlashCommandT], BaseSlashCommandT]]:
...The original can be found at https://github.com/FasterSpeeding/Tanjun/blob/7edec0fa4418718343826f9c6489bd817c4a9b47/tanjun/components.py#L590-L604 (yes I know the |
Collaborator
Author
|
Went through some issues that seemed partially related -- it looks like #9023 gets fixed by this too! |
Time for a quick run of mypy-primer!
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: Tanjun (https://github.com/FasterSpeeding/Tanjun)
- tanjun/abc.py:3139: error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables [misc]
- tanjun/abc.py:3205: error: Overloaded function implementation cannot satisfy signature 2 due to inconsistencies in how they use type variables [misc]
|
Collaborator
Author
|
Remade in #15320 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This fixes this following program:
This also fixes #9023.
Test Plan
I haven't added any tests yet, I plan to do that based on mypy primer output (still not sure this works...).